package com.lwt.Client;

import com.lwt.pojo.Grade;
import com.lwt.pojo.Student;
import com.lwt.service.GradeService;
import com.lwt.service.StudentService;
import com.lwt.service.serviceImpl.GradeServiceImpl;
import com.lwt.service.serviceImpl.StudentServiceImpl;

import java.util.List;
import java.util.Scanner;

/**
 * 利用+号折叠，非常必要。一个case必对应一个break。仔细检查。
 * @Author Li Weitong
 * @Date 2020/11/22 12:48
 */
public class Client {
    public static StudentService studentService = new StudentServiceImpl();
    public static GradeService gradeService = new GradeServiceImpl();
    public static Student student;
    public static Grade grade;

    public Client() {
        student = new Student();
        grade = new Grade(); // 这里不创建Grade对象，则会报空指针异常。
    }

    public static void main(String[] args) {
        Client client = new Client();

        String one = "1", two = "2", three = "3", four = "4";
        boolean ContinueFlag = true;
        while (true) {
            Scanner scanner = new Scanner(System.in);
            System.out.println("**********XX学生管理系统**********\n" +
                    "\t\t1.学生信息管理\n" +
                    "\t\t2.年级信息管理\n" +
                    "\t\t3.学生成绩管理\n" +
                    "********************************");
            System.out.print("请输入管理模块：");
            int input_number1 = scanner.nextInt();

            switch (input_number1) {
                case 1:
                    System.out.println("**********学生信息管理**********\n" +
                            "\t\t1.新增学生信息\n" +
                            "\t\t2.查询学生信息\n" +
                            "\t\t3.修改学生信息\n" +
                            "\t\t4.删除学生信息\n" +
                            "******************************\n");
                    System.out.print("请输入菜单项：");
                    int input_number2 = scanner.nextInt();
                    switch (input_number2) {
                        case 1:

                            System.out.println("**********新增学生信息**********");
                            System.out.print("请输入学生学号：");
                            int inputStudentId = scanner.nextInt();
                            System.out.print("请输入学生姓名：");
                            String inputStudentName = scanner.next();
                            System.out.print("请输入学生性别：");
                            String inputGender = scanner.next();
                            System.out.print("请输入年级编号：");
                            int inputGradeId = scanner.nextInt();
                            student.setStudentId(inputStudentId);
                            student.setStudentName(inputStudentName);
                            student.setGender(inputGender);
                            student.setGradeId(inputGradeId);
                            studentService.addStudent(new Student(student.getStudentId(), student.getStudentName(), student.getGender(), student.getGradeId()));
                            break;
                        case 2:
                            System.out.println("**********查询学生信息**********\n" +
                                    "\t\t1.查询全部信息\n" +
                                    "\t\t2.根据学号查询信息\n" +
                                    "\t\t3.根据姓名查询信息\n" +
                                    "\t\t4.根据年级编号查询信息\n" +
                                    "******************************");
                            System.out.print("请输入菜单项：");
                            Scanner scanner2 = new Scanner(System.in);
                            int input_number3 = scanner2.nextInt();
                            switch (input_number3) {
                                case 1:
                                    System.out.println("**********查询结果**********");
                                    List<Student> students = studentService.queryStudentList();
                                    for (Student student1 : students) {
                                        System.out.println(student1);
                                    }
                                    break;
                                case 2:
                                    System.out.print("请输入学生学号：");
                                    int studentIdQuery = scanner.nextInt();
                                    System.out.println("**********查询结果**********");
                                    System.out.println(studentService.queryStudentById(studentIdQuery));

                                    break;
                                case 3:
                                    System.out.print("请输入学生姓名：");
                                    String studentNameQuery = scanner.next();
                                    System.out.println("**********查询结果**********");
                                    System.out.println(studentService.queryStudnetByName(studentNameQuery));
                                    break;
                                case 4:
                                    System.out.print("请输入学生年级编号：");
                                    int gradeIdQuery = scanner.nextInt();
                                    System.out.println("**********查询结果**********");
                                    System.out.println(studentService.queryStudentByGradeId(gradeIdQuery));
                                    break;
                            }
                            break;
                        case 3:
                            System.out.println("**********修改学生信息**********");
                            System.out.print("请输入要修改的学生学号：");
                            int inputStudentIdUpdate = scanner.nextInt();
                            System.out.print("请输入修改后的学生姓名：");
                            String inputStudentNameUpdate = scanner.next();
                            System.out.print("请输入修改后的学生性别：");
                            String inputGenderUpdate = scanner.next();
                            System.out.print("请输入修改后的年级编号：");
                            int inputGradeIdUpdate = scanner.nextInt();
                            student.setStudentId(inputStudentIdUpdate);
                            student.setStudentName(inputStudentNameUpdate);
                            student.setGender(inputGenderUpdate);
                            student.setGradeId(inputGradeIdUpdate);
                            studentService.updateStudent(student);
                            break;
                        case 4:
                            System.out.println("**********删除学生信息**********");
                            System.out.print("请输入要删除的学生学号：");
                            int studentIdDelete = scanner.nextInt();
                            studentService.deleteStudentById(studentIdDelete);
                            break;
                }
                    break;
                case 2:
                    System.out.println("**********年级信息管理**********\n" +
                            "\t\t1.新增年级信息\n" +
                            "\t\t2.显示年级信息\n" +
                            "\t\t3.修改年级信息\n" +
                            "\t\t4.删除年级信息\n" +
                            "******************************");
                    System.out.println("请选择菜单项:");
                    int Grade_Number1 = scanner.nextInt();
                    switch (Grade_Number1){
                        case 1:
                            System.out.println("**********新增年级信息**********");
                            System.out.print("请输入年级编号：");
                            int inputAddGradeId = scanner.nextInt();
                            grade.setGradeId(inputAddGradeId);
                            System.out.print("请输入年级名称：");
                            String inputGradeName = scanner.next();
                            grade.setGradeName(inputGradeName);

                            gradeService.addGrade(grade);
                            break;

                        case 2:
                            System.out.println("**********年级信息**********");
                            System.out.println(gradeService.queryGradeList());
                            break;
                        case 3:
                            System.out.println("**********修改年级信息**********");
                            System.out.print("请输入要修改的年级编号：");
                            int inputUpdateGradeId = scanner.nextInt();
                            grade.setGradeId(inputUpdateGradeId);
                            System.out.print("请输入修改后的年级名称：");
                            String inputUpdateGradeName = scanner.next();
                            grade.setGradeName(inputUpdateGradeName);

                            gradeService.updateGrade(grade);
                            break;
                        case 4:
                            System.out.println("**********修改年级信息**********");
                            System.out.print("请输入要删除的年级编号：");
                            int inputDeleteGradeId = scanner.nextInt();

                            gradeService.deleteGradeById(inputDeleteGradeId);
                            break;
                    }

            }
        }

    }

}

